//秒杀

function throttle(fn, threshold = 250) {
  let last, timer;
  //使用last来记录上依次执行的时间戳
  return function () {
    let context = this;
    let args = arguments;
    let now = +new Date();
    if (last && now < last + threshold) {
      clearTimeout(timer);
      timer = setTimeout(function () {
        last = now;
        fn.apply(context, args);
      }, threshold);
    } else {
      last = now;
      fn.apply(context, args);
    }
  };
}
